import React, { Component } from 'react'
import { getSecondsLevelApi } from "@/api/goods"
import MyPubSub from "@/utils/pubsub";
import style from"./index.module.scss"
import { withRouter } from "react-router-dom";
 class ShowSide extends Component {
  // 获取二级分类
  state={
    subcateArr:[],
  }
  async Secondslevel(activekey) {
    let res = await getSecondsLevelApi({
      id: activekey
    });
    if (res.data.code === 200) {
      this.setState({
        subcateArr: res.data.subcate.subcategory
      })
      // console.log('MyPubSub', MyPubSub);
    }
    console.log("erjicaid", res);
  }
  componentDidMount() {
    MyPubSub.subscribe("transferFirstId", (activekey) => {
      this.Secondslevel(activekey)
    })
  }
  transferGoodsAll=(id)=>{
    // console.log(111);
    // console.log(id,this.props);
    this.props.history.push({pathname:"GoodsAll",search:`?id=${id}`})
  }
  render() {
    return (
      
        <div>
          {this.state.subcateArr.map((item)=>{
           return (
            <div key={item.id} className={style.ShowSide}>
              <h3 className={style.ShowSideh5}>{item.name}</h3>
              <ul className={style.ShowSidefiber}>
                {item.subNavs.map((subitem)=>{
                  return (
                      <li key={subitem.id} className={style.fiberli} onClick={()=>this.transferGoodsAll(subitem.id)}>
                        <img src={subitem.pic} alt={subitem.name} />
                        <p>{subitem.name}</p>
                      </li>
                  )
                })}
              </ul>
            </div>
          )
          })}
        </div>
     
    )
  }
}
export default withRouter(ShowSide)